(function ($){

	var popup,hide_action_popup;

	popup = (function () {

		function popup(){};

        //显示popup
        popup.prototype.open_popup = function (lock_div) {
        	var _this = this;
            
            if($(this).height() === $(window).height()){
                _this.addClass('popup_up');
                return;
            }

        	$('body').append('<div class="weui-mask"></div>');
            $('.weui-mask').addClass('weui-animate-fade-in').css({'z-index':800});
		 	_this.addClass('popup_up').on('animationend webkitAnimationEnd', function () {
                if(lock_div){$(lock_div).css('overflow','hidden');}
			    $('.weui-mask').on('click', function () {
			        hide_action_popup(_this,lock_div);
			    });
	        });
        };

        //关闭popup
        popup.prototype.close_popup = function (lock_div) {
        	var _this = this;
        	hide_action_popup(_this,lock_div);
        };
		
		return popup;
	})();

	//关闭popup
	hide_action_popup = function(_this,lock_div){
		$('.weui-mask').addClass('weui-animate-fade-out');
        _this.addClass('popup_down').on('animationend webkitAnimationEnd', function () {
            $('.weui-mask').remove();
            _this.removeClass('popup_up popup_down');
            _this.off('animationend webkitAnimationEnd');
            if(lock_div){$(lock_div).css('overflow','auto')}
        });
	}
	
	/**
     * 添加到$.fn
     */
    $.extend($.fn,{
    	open_popup:new popup().open_popup,
    	close_popup:new popup().close_popup
   	});
})($);